<template>
  <el-dialog :title="formData.id?'编辑停车位':'添加停车位'" :visible="showDialog" @close="close">
    <el-form ref="form" label-width="120px" :model="formData">
     
      <!-- <el-form-item label="停车开始时间"  prop="startTime">
        <el-input v-model="formData.startTime" />
      </el-form-item>
      
      <el-form-item label="车牌号"  prop="licensePlateNumber">
        <el-input v-model="formData.licensePlateNumber" />
      </el-form-item> -->

      <el-form-item label="充电桩">
        <el-select v-model="formData.isChargingPile">
          <el-option label="有" :value="1" />
          <el-option label="无" :value="0" />
        </el-select>
      </el-form-item>

      <el-form-item label="空闲状态">
        <el-select v-model="formData.isFree">
          <el-option label="是" :value="0" />
          <el-option label="否" :value="1" />
        </el-select>
      </el-form-item>

      <el-form-item label="停车场">
        <el-select v-model="formData.parkingId" :label="formData.name">
          <el-option v-for="item in parking_lot_list" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
    </el-form>
    <el-row type="flex" justify="center">
      <el-button type="primary" size="small" @click="submit">确定</el-button>
      <el-button size="small" @click="close">取消</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import { addProperties, editPropperties, getPropertiesById } from '../../../api/properties'
import { getSpaceList, getParkingLotList, selectById, add, update} from '../../../api/space'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { quillEditor } from 'vue-quill-editor'
export default {
  components: {
    quillEditor
  },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    agentList: {
      type: Array,
      default() {
        return []
      }
    },
    categoryList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      formData: {
      },
      inputVisible: false,
      inputValue: '',
      imgList: false,
      imgUrl: '',
      parking_lot_list: []
    }
  },
  methods: {
    // 数据回显
    async getInfo(id) {
      var params = {
        id: id
      }
      const res = await selectById(params)
      console.log("formData", res.data.data)
      this.formData = res.data.data
      
    },
    async parkingLotList() {
      const res = await getParkingLotList()
      console.log("res.data", res.data.data)

      var parkinglot = []
      for (var i = 0; i < res.data.data.length; i ++) {
        console.log(res.data.data[i])
        var message = {
          "id": res.data.data[i].id,
          "name": res.data.data[i].name
        }
        console.log("message", message)
        parkinglot.push(message)
      }
      this.parking_lot_list = parkinglot
    },
    // 添加房产
    async submit() {
      await this.$refs.form.validate()
      if (this.formData.id) {
        await update(this.formData)
      } else {
        await add(this.formData)
      }
      this.$message.success('操作成功')
      this.close()
      this.$emit('updateFn')
    },
    close() {
      this.$emit('update:showDialog', false)
      this.formData = {
        id: '',
        startTime: '',
        licensePlateNumber: '',
        isChargingPile: [],
        isFree: '',
        parkingId: '',
        name: ''
      }
      this.$refs.form.resetFields()
    },
    handleClose(tag) {
      this.formData.tags.splice(this.formData.tags.indexOf(tag), 1)
    },

    showInput() {
      this.inputVisible = true
      this.$nextTick(_ => {
        this.$refs.saveTagInput.$refs.input.focus()
      })
    },

    handleInputConfirm() {
      const inputValue = this.inputValue
      if (inputValue) {
        // this.tagsList.push(inputValue)
        this.formData.tags.push(inputValue)
      }
      this.inputVisible = false
      this.inputValue = ''
    }
  },
  async created() {
    this.parkingLotList()
  }
}
</script>
<style lang="scss" scoped>
.el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }

</style>
